package com.feige.web.result;


import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.feige.base.dto.BaseDto;
import com.feige.base.po.IPersistence;
import com.feige.base.vo.BaseVo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.List;


/**
 * @author feige
 */
@ApiModel(value = "分页信息")
@Data
public class PageInfo<T extends IPersistence> implements BaseVo, BaseDto<T> {

    private static final long serialVersionUID = -5377563954765125091L;

    @ApiModelProperty(
            value = "当前页",
            example = "1"
    )
    private int pageNum = 1;

    @ApiModelProperty(
            value = "每页大小",
            example = "20"
    )
    private int pageSize = 20;

    @ApiModelProperty(
            value = "总页数"
    )
    private long pages;

    @ApiModelProperty(
            value = "总条数"
    )
    private long total;

    @ApiModelProperty(
            value = "是否需要查询总数",
            example = "false"
    )
    private boolean needTotal = true;

    private List<OrderItem> orders;

    public Page<T> toMpPage(){
        Page<T> tPage = new Page<>();
        tPage.setCurrent(this.getPageNum());
        tPage.setSize(this.getPageSize());
        tPage.setOrders(this.getOrders());
        tPage.setSearchCount(this.isNeedTotal());
        return tPage;
    }


    public PageInfo<T> fill(Page<T> tPage){
        this.setPages(tPage.getPages());
        this.setTotal(tPage.getTotal());
        return this;
    }

}
